﻿@*
	Iván Loire - www.iloire.com
	Please readme README file for license terms.

	ASP.NET MVC3 ACME Invocing app (demo app for training purposes)
*@

@model Invoice

@{
    var entityname = ViewBag.IsProposal ? "Proposal" : "Invoice";
}

<script>
    $(document).ready(function () {

        $(".proposalDetails").cleditor()[0].focus();

        $('#editInvoiceNumber').live('click',function () {
            $('#InvoiceNumber').attr('disabled', '');
        });
    });
</script>
  <fieldset>
        <legend>@entityname edition</legend>

        @Html.HiddenFor(model => model.InvoiceID)

        @if (!ViewBag.IsProposal)
        {
         <div class="clearfix">
            @Html.LabelFor(model => model.InvoiceNumber)
        
            <div class="input">
                @if (Model != null && Model.InvoiceID > 0)
                {
                    <text>
                        @Html.TextBoxFor(model => model.InvoiceNumber, new { @class = "small disabled", disabled = true })
                        @Html.HiddenFor(model => model.InvoiceNumber)
                        <a id="editInvoiceNumber" href="#">change invoice id (I know what I am doing)</a>
                    </text>
                }
                else
                { 
                     <text>
                        @Html.TextBoxFor(model => model.InvoiceNumber, new { @class = "small" })
                    </text>
                }
            
                @Html.ValidationMessageFor(model => model.InvoiceNumber)
            </div>
		</div>
        }


        <div class="clearfix">
            @Html.LabelFor(model => model.CustomerID, "Customer")
        
            <div class="input chzn-select">
                @Html.DropDownList("CustomerID", String.Empty)
                @Html.ValidationMessageFor(model => model.CustomerID)
            </div>
		</div>

        <div class="clearfix">
            @Html.LabelFor(model => model.Notes)
        
            <div class="input">
                @Html.TextAreaFor(model => model.Notes, new { @class = "proposalNotes" })
                @Html.ValidationMessageFor(model => model.Notes)
            </div>
		</div>

        @*@if (Model.IsProposal) { *@
          <div class="clearfix">
            @Html.LabelFor(model => model.ProposalDetails)
        
            <div class="input">
                @Html.TextAreaFor(model => model.ProposalDetails, new { @class="proposalDetails"})
                @Html.ValidationMessageFor(model => model.ProposalDetails)
            </div>
		   </div>
        @*}*@

        <div class="clearfix">
            @Html.LabelFor(model => model.TimeStamp)
        
            <div class="input">
                @Html.EditorFor(model => model.TimeStamp, "Calendar")
                @Html.ValidationMessageFor(model => model.TimeStamp)
            </div>
		</div>

        <div class="clearfix">
            @Html.LabelFor(model => model.DueDate)
        
            <div class="input">
                @Html.EditorFor(model => model.DueDate, "Calendar")
                @Html.ValidationMessageFor(model => model.DueDate)
            </div>
		</div>

         <div class="clearfix">
            @Html.LabelFor(model => model.AdvancePaymentTax)
        
            <div class="input">
                @Html.EditorFor(model => model.AdvancePaymentTax) %
                @Html.ValidationMessageFor(model => model.AdvancePaymentTax)
            </div>
		</div>

        <div class="clearfix">
            @Html.LabelFor(model => model.Paid)
        
            <div class="input">
                @Html.EditorFor(model => model.Paid)
                @Html.ValidationMessageFor(model => model.Paid)
            </div>
		</div>

		<div class="actions">
            <input type="submit" class="btn primary" value="Save" />
               @if (Model != null && Model.InvoiceID > 0)
               {   <text>
                @Html.ActionLink("Delete", "Delete", new { id = Model.InvoiceID, proposal = ViewBag.IsProposal }, new { @class = "btn" })
                </text>
               }
            @Html.ActionLink("Print", "Print", "Invoice", new { id = Model.InvoiceID, proposal = ViewBag.IsProposal }, new { target = "_blank", @class = "btn" })

            @if (!Model.IsProposal)
            {  //even if this is an invoice, we let be printed with proposal format
                @Html.ActionLink("Print as proposal", "Print", "Invoice", new { id = Model.InvoiceID, proposal = true }, new { target = "_blank", @class = "btn" })
            }
            
            @if (ViewBag.ShowMakeInvoice == true) { 
                @Html.ActionLink("Make invoice", "Edit", "Invoice", new { id = Model.InvoiceID, makeinvoice = true }, new { @class = "btn" })
            }

            @if (ViewBag.ShowMakeProposal == true) { 
                @Html.ActionLink("Make proposal", "Edit", "Invoice", new { id = Model.InvoiceID, makeproposal = true }, new { @class = "btn" })
            }
        </div>
    </fieldset>